// fenxiao/index/index.js
var app = getApp();
const utils = require('../../../utils/pay.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lists:{},
    platform:"",
    showModel: false,
    inputMoney:0,
    cash: 0,
    uid: '',
    showLoading: true
  },
  getShipInfo: function(){
    let that = this;
    wx.request({
      url: app.globalData.host + '/api/Ship/GetCashInfo?uid='+ app.globalData.userInfo.Uid +'&storeId=' + app.globalData.storeId,
      success: function(res){
        that.setData({
          showLoading: false
        })
        if(res.data.Code == 0){
          if(res.data.Data && res.data.Data.info){
            let info = res.data.Data.info;
            that.setData({
              uid: info.Uid,
              cash: info.Cash
            })
          }
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      platform: app.globalData.platform
    })
    this.getShipInfo();
  },

  showModel: function () {
    this.setData({ showModel: !this.data.showModel })
  },

  bindInputValue: function (e) {
    this.setData({
      inputMoney: parseFloat(e.detail.value)
    })
  },
  
  checkInput: function(){
    if (!this.checkMoney(this.data.inputMoney)) {
      wx.showModal({
        title: '提示',
        content: '请输入50-9900整数',
        showCancel: false,
      })
      return
    }
  },

  //金额验证
  checkMoney: function (obj){
    if(!obj){
      return false;
    }else{
      return typeof obj === 'number' && obj % 50 === 0;//是整数，则返回true，否则返回false
    }
  },
  toRecordList: function(e){
    let type = e.currentTarget.dataset.type;
    wx.navigateTo({
      url: '../recharge-list/index?direction='+type,
    })
  },

  //安卓手机现金直冲
  submitAccountBalanceOrder: function () {
    if (!this.checkMoney(this.data.inputMoney)){
      wx.showModal({
        title: '提示',
        content: '请输入50-9900整数',
        showCancel: false,
      })
      return
    }
    wx.showLoading({
      title: '充值中',
      mask: true
    })
    wx.request({
      url: app.globalData.host + '/api/Order/SubmitStaffOrder',
      data: {
        uid: app.globalData.userInfo.Uid,
        money: this.data.inputMoney,
        count: 1,
        orderType: 3
      },
      method: 'POST',
      success: function (res) {
        wx.hideLoading();
        if (res.data.Code == 0) {
          utils.wxcashpay(app, res.data.Data)
        } else {
          wx.showModal({
            title: '提示',
            content: res.data.Message,
            showCancel: false
          })
        }
      }
    })
  }
})